package com.wenwei.sharebox.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Window;
import android.widget.TextView;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.adapter.ReplenishmentAdapter;
import com.wenwei.sharebox.base.AtyContainer;
import com.wenwei.sharebox.base.BaseActivity;
import com.wenwei.sharebox.bean.DeviceGoodsBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;
import com.wenwei.sharebox.utils.RogerSPUtils;
import com.wenwei.sharebox.view.CustomDelDialog;
import com.wenwei.sharebox.view.OptionDialog;

import org.json.JSONObject;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/13.
 */
public class ReplenishmentActivity extends BaseActivity implements ReplenishmentAdapter.CallBack {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.recycler)
    RecyclerView recycler;

    ReplenishmentAdapter mAdapter;
    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_replenishment;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("补货");
        recycler.setLayoutManager(new GridLayoutManager(mContext,3));
        mAdapter = new ReplenishmentAdapter();
        mAdapter.setCallBack(this);
        recycler.setAdapter(mAdapter);
    }

    @OnClick(R.id.base_back)
    public void onViewClicked() {
        finish();
    }
    private String deviceNum;
    @Override
    protected void init() {
        super.init();
        deviceNum = getIntent().getStringExtra("deviceCode");
    }

    @Override
    protected void initData() {
        super.initData();
        getDeviceGoods();
    }

    private BaseSubscriber<ArrayList<DeviceGoodsBean>> deviceGoodsSubscriber;
    private void getDeviceGoods(){
        deviceGoodsSubscriber = new BaseSubscriber<ArrayList<DeviceGoodsBean>>(mContext) {
            @Override
            public void onSuccess(ArrayList<DeviceGoodsBean> deviceGoodsBeen) {
                mAdapter.setData(deviceGoodsBeen);
                mAdapter.notifyDataSetChanged();
            }
        };
        try{

            ApiManager.getInstance().getDeviceShops(deviceGoodsSubscriber,1,12,"",deviceNum);
        }catch (Exception e){}
    }

    @Override
    public void onItemClick(int shopId, int deviceSmallId) {

        if (mExitLoginDialog == null) {
            mExitLoginDialog = new OptionDialog(mContext);
            mExitLoginDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        }
        mExitLoginDialog.setMsg(shopId,deviceSmallId);
        mExitLoginDialog.show();
    }

    private OptionDialog mExitLoginDialog;
}
